#! /usr/bin/python3
# -*- coding: UTF-8 -*-

if __name__ == "__main__":
	raise Exception("不支持从这里调用")

__version__ = "1.0"
__all__ = []

from com.mousechsh.business.lib.MouseChshAuthorizationAnnotition import MouseChshRemoteAuthorizationAnnotition
from com.mousechsh.business.lib.model.MouseChshMessageModel import MouseChshMessageModel
from com.mousechsh.common.data.MouseChshDao import MouseChshDao
from com.mousechsh.common.io.db.MouseChshPostgresql import MouseChshPostgresql
from com.mousechsh.common.middle.http.MouseChshHttpHeader import mousechsh_http_header_accept_language_annotation
from com.mousechsh.common.middle.rest_api.MouseChshRestApi import mousechsh_rest_api_annotation
from com.mousechsh.common.middle.router.MouseChshCorsAnnotition import mousechsh_cors_annotation
from com.mousechsh.common.middle.router.MouseChshHttpRouter import mousechsh_http_router_annotation


@mousechsh_http_router_annotation(method=['POST', 'OPTIONS'], path='/message/get')
@mousechsh_cors_annotation()
@mousechsh_http_header_accept_language_annotation()
@MouseChshRemoteAuthorizationAnnotition()
@mousechsh_rest_api_annotation()
def _getMessage(params):
	lang = params.get('lang', 'zh-cn')
	db = MouseChshPostgresql()
	db.connect()
	data = db.get(
		'''
	   SELECT
		   "C_Id",
		   "C_CrOn",
		   "C_CrBy",
		   "C_MoOn",
		   "C_MoBy",
		   "C_RvOn",
		   "C_RvBy",
		   "C_St",
		   "C_Owner",
		   "C_Flag",
		   "L_Scheme",
		   "X_Data",
		   "X_Property",
		   "L_Member_Id_From",
		   "L_App_Id_From",
		   "L_Member_Id_To",
		   "L_App_Id_To",
		   "C_Title",
		   "L_Template_Id",
		   "X_Content",
		   "C_FlagReceive",
		   "C_FlagRead",
		   "C_Log"
	   FROM "A_Message"."T_Template"
	   ORDER BY "C_CrOn" DESC
	   LIMIT 100
		   ''', {
			'lang': lang
		}
	)
	db.close()
	dao = MouseChshDao()
	dao.set_model(MouseChshMessageModel)
	messages = dao.parse(data)
	return messages
